(function($){
    $.fn.serializeJson=function(){
        var serializeObj={};
        var array=this.serializeArray();
        // var str=this.serialize();
        $(array).each(function(){
            if(serializeObj[this.name]){
                if($.isArray(serializeObj[this.name])){
                    serializeObj[this.name].push(this.value);
                }else{
                    serializeObj[this.name]=[serializeObj[this.name],this.value];
                }
            }else{
                serializeObj[this.name]=this.value;
            }
        });
        return serializeObj;
    };
})(jQuery);

$(document).ready(function(){
    var ueditor = UE.getEditor('ueditor', {wordCount: true});
    setTimeout(function () {
        ueditor.setContent($('#introduceHidden').html(),false);
    },500);
    $('#submitBtn').click(function (e) {
        e.preventDefault();
        var data=$("#travelAgencyForm").serializeJson();//表单序列化
        data.introduce = ueditor.getContent();
        jQuery.ajax({
            dataType : 'json',
            type:'post',
            url : $('#travelAgencyForm').attr('action'),
            data :data,
            success : function(result) {
                if(result.code=='200'){
                    bootbox.confirm({
                        title:'提示信息',
                        message: result.message+'是否继续添加？',
                        buttons: {
                            confirm: {
                                label: '是',
                                className: 'btn-success'
                            },
                            cancel: {
                                label: '否',
                                className: 'btn-default'
                            }
                        },
                        callback: function (result) {
                            if(result){
                                if($('input[name="id"]').val()==""){
                                    $('#travelAgencyForm')[0].reset();
                                    ueditor.setContent('');
                                }else{
                                    // var url = $('#addUrl').val();
                                    window.location.href="/travelagency/input.do";
                                }
                            }else{
                                window.location.href="/travelagency/list.do";
                            }
                        }
                    });
                }else{
                    bootbox.alert(result.message);
                }
            },
            error:function () {
                bootbox.alert('请求失败！');
            }
        });
    });
    $('.datepicker').datepicker({
        todayBtn : "linked",
        autoclose : true,
        todayHighlight : true,
        format:'yyyy-mm-dd',
        language : 'zh-CN'
    });
    $('#resetBtn').click(function(e) {
        $('#travelAgencyForm')[0].reset();
    });
    // var cusBox = new customerBox();
    $('#customerConfirm').click(function (e) {
        // alert('ss');
        // cusBox.show();
        // alert('sdds');
        $('#modal-table').modal('hide');
        $('#linkMan').val('谢霆锋');
    });

});